package com.jing21.learn.fs.config;

import com.aliyun.oss.OSSClient;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * Create By zhengjing on 2017/11/7 10:50
 */
@Configuration
@ConfigurationProperties("alibaba.oss")
@Data
public class OssClientConfiguration {

    static List<String> list = new ArrayList<>();

    // 目前只有"cn-hangzhou"这个region可用, 不要使用填写其他region的值
    private static final String REGION_CN_HANGZHOU = "cn-hangzhou";

    public static  String ROLE_ARN;
    static {
        list.add("jing21-image");
        list.add("jing21-static");
    }
    @NotNull
    private String endpoint;
    @NotNull
    private String accessKeyId;

    @NotNull
    private String accessKeySecret;

    /**
     * sts key Id
     */
    @NotNull
    private String stsAccessKeyId;
    /**
     *
     */
    @NotNull
    private String stsAccessKeySecret;

    @NotNull
    private String stsRoleArn;

    @Bean
    public OSSClient ossClient() {
        return new OSSClient(endpoint, accessKeyId, accessKeySecret);
    }


    @Bean
    public DefaultAcsClient defaultAcsClient(){
        IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, stsAccessKeyId, stsAccessKeySecret);
        ROLE_ARN = stsRoleArn;
        return new DefaultAcsClient(profile);
    }

}
